import socket
import sys

MSGLEN = 16

class MySocket(object):
    def __init__(self, sock=None):
        if sock is None:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        else:
            self.sock = sock


    def connect(self, host, port):
        self.sock.connect((host, port))

    def mysend(self, msg):
        sent = self.sock.send(msg)
        if sent == 0:
            raise RuntimeError("socket connection broken")

    def myreceive(self, size):
        msg = self.sock.recv(size)
        return msg

class User(MySocket):
    def connect(self):
        super(User, self).connect("127.0.0.1", 9099)

class Event(MySocket):
    def connect(self):
        super(Event, self).connect("127.0.0.1", 9090)

